package com.egor.services.impl;

import com.egor.data.entity.Order;
import com.egor.data.enums.OrderStatus;
import com.egor.data.repository.OrderRepository;
import com.egor.services.OrderService;
import lombok.AllArgsConstructor;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@AllArgsConstructor
public class OrderServiceImpl implements OrderService {
    private final OrderRepository orderRepository;

    @Override
    public List<Order> listAll(Pageable pageable) {
        return orderRepository.findAll(pageable).getContent();
    }

    @Override
    public void save(Order order) {
        orderRepository.save(order);
    }

    @Override
    public void delete(Order order) {
        orderRepository.delete(order);
    }

    @Override
    public List<Order> findAll(String text, OrderStatus orderStatus, Pageable pageable) {
        return orderRepository.searchByCategory(text, orderStatus, pageable).getContent();
    }

    @Override
    public List<Order> findByStatus(OrderStatus status, Pageable pageable) {
        return orderRepository.findByOrderStatus(status, pageable).getContent();
    }
}
